// eslint.config.js
import js from "@eslint/js";
import globals from "globals";
import vuePlugin from "eslint-plugin-vue";
import vueParser from "vue-eslint-parser"; // 新增vue专用解析器
import tseslint from "@typescript-eslint/eslint-plugin";
import tsParser from "@typescript-eslint/parser";
// import espree from 'espree'

export default [
  // 基础配置
  {
    ignores: [
      "*.sh",
      "node_modules",
      "*.md",
      "*.woff",
      "*.ttf",
      ".vscode",
      ".idea",
      "dist",
      "/public",
      "/docs",
      ".husky",
      ".local",
      "/bin",
      "/src/mock/*",
      "stats.html"
    ]
  },

  // JavaScript 基础规则
  js.configs.recommended,

  // 环境配置
  {
    languageOptions: {
      globals: {
        ...globals.browser,
        ...globals.node,
        ...globals.es2020
      },
      parserOptions: {
        ecmaVersion: 2020,
        sourceType: "module",
        jsxPragma: "React",
        ecmaFeatures: {
          jsx: true
        }
      }
    }
  },

  // TypeScript 配置
  {
    files: ["**/*.ts"],
    languageOptions: {
      parser: tsParser
    },
    plugins: {
      "@typescript-eslint": tseslint
    },
    rules: {
      "@typescript-eslint/no-unused-vars": "off",
      "@typescript-eslint/no-empty-function": "error",
      "@typescript-eslint/prefer-ts-expect-error": "error",
      "@typescript-eslint/ban-ts-comment": "error",
      "@typescript-eslint/no-inferrable-types": "off",
      "@typescript-eslint/no-namespace": "off",
      "@typescript-eslint/no-explicit-any": "off",
      "@typescript-eslint/ban-types": "off",
      "@typescript-eslint/no-var-requires": "off",
      "@typescript-eslint/no-non-null-assertion": "off"
    }
  },

  // Vue 配置
  {
    files: ["**/*.vue"],
    languageOptions: {
      parser: vueParser,
      parserOptions: {
        parser: {
          ts: "@typescript-eslint/parser", // 解析 <script lang="ts">
          js: "espree" // 解析普通 JS
        }
      }
    },
    plugins: {
      vue: vuePlugin
    },
    rules: {
      "vue/v-slot-style": "error",
      "vue/no-mutating-props": "error",
      "vue/custom-event-name-casing": "error",
      "vue/html-closing-bracket-newline": "error",
      "vue/attribute-hyphenation": "error",
      "vue/attributes-order": "off",
      "vue/no-v-html": "off",
      "vue/require-default-prop": "off",
      "vue/multi-word-component-names": "off",
      "vue/no-setup-props-destructure": "off"
    }
  },

  // 通用规则
  {
    rules: {
      "no-unused-vars": "off", // 关闭基础 ESLint 的检查
      "no-var": "error",
      "no-multiple-empty-lines": ["error", { max: 1 }],
      "prefer-const": "off",
      "no-use-before-define": "off"
    }
  }
];
